<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/register.css">
    <script src="./js/jquery.min.js"></script>
    <title>注册</title>
    <style>
        #msg {
            width: 100%;
            line-height: 40px;
            font-size: 14px;
            text-align: center;
            position: absolute;
            z-index: 999;
        }

        .container {
            width: 310px;
            position: relative;
        }
    </style>
</head>

<body>
    <div class="reg-log-cls">
        <div class="prefect-header-box">
            <div class="inter-header">
                <div class="inter clearfix">
                    <dt class="fl">
                        <a href="./index.html">
                            <i class="icon-login-logo"></i>
                        </a>
                    </dt>
                    <dd class="fr">
                        <ul>
                            <li>
                                销售热线：
                                <span class="color-blue">400-810-9528</span>
                            </li>
                            <li>
                                客服热线：
                                <span class="color-blue">400-886-9528</span>
                            </li>
                            <li>
                                <a href="">服务中心</a>
                            </li>
                        </ul>
                    </dd>
                </div>
            </div>
        </div>
    </div>

    <div class="prefect-center register-center">
        <div class="content prefect-main clearfix">
            <div class="edz-company-mian fl">
                <a
                    href="./login.html">
                    <div id="handleBtnId" class="comp-handle-btn">立即登录</div>
                </a>
            </div>
            <div class="prefect-info-mian fr">
                <dl class="info-tit clearfix">
                    <dt class="fl">易点租会员注册</dt>
                    <dd class="fr">已有账号？去
                        <a
                            href="./login.html">登录</a>
                    </dd>
                </dl>
                <ul class="prefect-form register-form clearfix" id="regform">
                    <li>
                        <span class="form-tit">绑定手机号</span>
                        <form id="registerform">
                            <input id="phone" type="text" placeholder="请输入手机号码" autocomplete="off" class="login-text error"
                            require="true" valid="mobilePhone" errortarget="phoneError" error="手机号码格式不正确"
                            emptyerror="请输入手机号码" invalid="true" name="tel" onblur="return check_tel()">
                        </form>
                        
                    </li>
                    <li class="form-error">
                        <span id="phoneError" class="show">
                            <i class="icon-prefect-error" id="tel"></i>
                        </span>
                    </li>
                    <div class="container">
                        <div id="captcha" style="position: relative"></div>
                        <div id="msg"></div>
                    </div>
                    <script src="./js/sliding.js"></script>
                    <script>
                        jigsaw.init(document.getElementById('captcha'), function () {
                            document.getElementById('msg').innerHTML = ''
                        })
                    </script>
                    <li class="form-error imgCode-error"></li>
                    <li>
                        <span class="form-tit">短信验证码</span>
                        <input id="smsCode" type="text" placeholder="请输入短信验证码" autocomplete="off"
                            class="code-input error" require="true" valid="smsCode" errortarget="smsCodeError"
                            error="短信验证码不正确" emptyerror="请输入短信验证码" onblur="return check_yanzheng()" name="yz">
                        <a class="verification sure-num" id="smsCodeBtn">获取验证码</a>
                    </li>
                    <li class="form-error">
                        <span id="phoneError" class="show">
                            <i class="icon-prefect-error" id='yz'>
                            </i>
                        </span>
                    </li>
                    <li>
                        <span class="form-tit form-mtit">设置密码</span>
                        <input id="password" type="password" placeholder="请输入密码" autocomplete="off"
                            class="fake-autofill-input" require="true" valid="passwordLogin" errortarget="psderrortip"
                            error="密码格式不正确（要求8-32位数字与字母结合）" emptyerror="请输入密码" name="pwd" onblur="return check_pwd()" form="registerform">
                    </li>
                    <li class="form-error">
                        <span id="pwd"></span>
                    </li>
                    <li class="register-green">注册即代表同意
                        <a href="" target="_blank">《易点租账户注册协议》</a>
                    </li>
                    <li>
                        <button  class="button prefect-button" id="submitBtn" form="registerform" type="button">开始实现企业轻资产运营</button>
                    </li>
                </ul>
            </div>
        </div>
    </div>


    <div class="foot">
        <p class="footOne">© Copyright Reserved 2014-2019　| &nbsp;&nbsp;<a href=""><img src="./image/login/guohui.png"> 京公网安备
                11010102002019号</a> |　京ICP备14057387号-1　|　北京易点淘网络技术有限公司&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""><i
                    class="unit"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""><i class="enterprise"></i></a>
        </p>
        <p class="footTwo">办公地址： 北京市海淀区西二旗大街39号融通高科大厦二层 易点租</p>
        <p class="footThree">
            <a href="">北京退换机地址</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="">上海退换机地址</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="">深圳退换机地址</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="">武汉退换机地址</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        </p>
    </div>
    <script>
        function check_tel() {
            var tel = document.getElementsByName('tel')[0].value
            var ptn_tel = /^1[0-9]\d{9}$/;
            if (tel) {
                if (!tel.match(ptn_tel)) {
                    document.getElementById('tel').innerHTML = '手机号码格式不正确'
                    return false;
                } else {
                    var user_name = $("#phone").val()
                    var flage
                        $.ajax({
                            url:"http://localhost/yidianzu/API/register2.php",
                            data:{user_name:user_name},
                            async: false,
                            success:function(data){
                                if(data=='true'){
                                    document.getElementById('tel').innerHTML = '该手机号已被注册'
                                    flage = false
                                }else{
                                    document.getElementById('tel').innerHTML = ''
                                    flage = true;
                                }
                            }
                        })
                        return flage
                        if(flage){
                            return true
                        }else{
                            return false
                        }
                    }
                    
                }
             else {
                document.getElementById('tel').innerHTML = '请输入手机号码'
                return false
            }
        }




        function check_yanzheng() {
            var yz = document.getElementsByName('yz')[0].value
            var ptn_yz = /[0-9]\d{5}$/;
            if (yz) {
                if (!yz.match(ptn_yz)) {
                    document.getElementById('yz').innerHTML = '短信验证码不正确'
                    return false;
                } else {
                    document.getElementById('yz').innerHTML = ''
                    return true;
                }
            } else {
                document.getElementById('yz').innerHTML = '请输入短信验证码'
            }
        }




        function check_pwd() {
            var user_pwd = $("#password").val()
            var ptn_pwd = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,32}$/;
            if (user_pwd) {
                if (!user_pwd.match(ptn_pwd)) {
                    document.getElementById('pwd').innerHTML = '密码格式不正确（要求8-32位数字与字母结合）'
                    return false;
                } else {
                    document.getElementById('pwd').innerHTML = ''
                    return true;
                }
            } else {
                document.getElementById('pwd').innerHTML = '请输入密码'
                return false
            }
        }

        $("#submitBtn").click(function () {
            var user_name = $("#phone").val()
            var user_pwd = $("#password").val()
            if (user_name == null || user_name == "") {
                document.getElementById('tel').innerHTML = '请输入手机号码'
            }
            if (user_pwd == null || user_pwd == "") {
                document.getElementById('pwd').innerHTML = '请输入密码'
            }
            if (user_name && user_pwd) {
                if (check_tel() && check_pwd()) {
                    $.ajax({
                        type: "get",   //提交的方法
                        url: "http://localhost/yidianzu/API/register.php", //提交的地址  
                        data: { user_name: user_name, user_pwd: user_pwd },    
                        success: function (data) {  //成功
                            console.log(88)
                            if (data == 'false') {
                                alert("注册失败")
                            } else {
                                window.location.href = "./ucenter.html?user_name="+user_name
                            }
                        }
                    });
                }

            }

        }); 
    </script>
</body>

</html>